<?php


declare (strict_types=1);

namespace app\common\service\bangdou;
use app\common\library\helper;
use app\common\service\bangdou\Common as CommonService;

/**
 * @time:2023/11/14 17:38
 * @Author:wuqicheng
 */
class BdMember extends CommonService
{

    /**
     * 系统向邦豆生活提交会员信息，返回邦豆用户信息
     * @param $unionId
     * @param null $phone
     */
    public static function getBangDouUserInfo($unionId,$phone=null)
    {
        $user_info = array('unionid'=>$unionId,'phone'=>$phone,'timestamp'=>time());
        $sign = self::getBangDouApiSign($user_info);
        $user_info['sign'] = $sign;
        $url = app()->config->get('app.bd_api_url').'/Member/Register/register';
        $header = array('Content-Type: application/json');
        $result = helper::httpRequest($url, json_encode($user_info), $header);
        $res = json_decode($result, true);
        if($res['state']==true){
            return $res['data'];
        }
        return false;
    }

    /**
     * 通过bd_uid获取三券值
     * @param $bd_uid
     * @return false|mixed
     */
    public static function getUserProperty($bd_uid){
        $params = self::createToken($bd_uid);
        $params['timestamp'] = time();
        $sign = self::getBangDouApiSign($params);
        $params['sign'] = $sign;
        $url = app()->config->get('app.bd_api_url').'/Member/Member/info';
        $headers = [
            'Content-Type: application/json',
            "Authorization: Bearer {$params['token']}"
        ];
        $result = helper::httpRequest($url, json_encode($params), $headers);
        $res = json_decode($result, true);
        if($res['state']==true){
            return $res['data'];
        }
        return false;
    }

}